home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 440 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: "Wil Evers" <wil@ittpub.nl>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Legal C++ code?
  5. Date: 22 Feb 1996 09:15:03 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <0099E49564818440.3D607462@ittpub.nl>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Thu, 22 Feb 96 10:02:52 WET
  11. X-Vms-Mail-To: IN%"std-c++@ncar.ucar.edu"
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMSykpky4NqrwXLNJAQExJwH+O9X0B6B+rqof8wPov/g/LW21D5sPHT5e
  14.     Osi+PKjEvg/2+6+jRqUB0p9eIR+k3FpvQtBjE/5HqvwwVYLE+5dQOQ==
  15.     =aGQn
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. In article <4gbilr$38m@dub-news-svc-1.compuserve.com> 71247.3221@compuserve.com (Don Wallace) writes:
  19.  
  20. [example of derived class calling pure virtual function in base class]
  21.  
  22. > I suspect that this is perfectly legal C++ code. Every statement taken
  23. > individually is correct. But even if it linked, the net effect of
  24. > calling bar.foo() would be to attempt to activate a pure virtual
  25. > function (In Borland C++ this generates a RTL program halt - it says
  26. > 'pure virtual function called'.)
  27. > The statement/function 
  28. > >    int foo() { return Foo::foo(); }
  29. > refers to Foo::foo() which is inherently not defined. Hence the link
  30. > error.
  31.  
  32. This is a common misconception: a pure virtual function may or may
  33. not have a definition. It it doesn't have a definition and you try to 
  34. call it anyway, you will probably get a link-time- or run-time error or
  35. your program could just go haywire; if it does have a definition, then
  36. calling it is perfectly OK. The canonical example of a pure virtual
  37. function that does have a definition is a pure virtual destructor: 
  38. without a body, such a class would not be very useful.
  39.  
  40. - Wil
  41.  
  42. Wil Evers, ITT Publitec Research and Development, <wil@ittpub.nl>
  43. ---
  44. [ To submit articles: Try just posting with your newsreader.  If that fails,
  45.                       use mailto:std-c++@ncar.ucar.edu
  46.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  47.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  48.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  49. ]
  50.